﻿#include "stdafx.h"
#include "InfoManageService.h"
#include "UserDB.h"
#include "StudentDB.h"
#include "TeacherDB.h"
/*
   这里是个人信息管理系统模块
*/
InfoManageService::InfoManageService()
{
}

std::string InfoManageService::changePassword(User &u, const std::string &op , const std::string &np,const std::string &npr){
	UserDB uDB;
	string oldPassword = uDB.selectByUserId(u.getUserId()).getPassword();
	if (oldPassword == op)//旧密码和该用户数据库里的密码匹配
	{
		if (np == npr) {//两次输入的新密码相等
			u.setPassword(np);
			uDB.update(u);
			cout << "密码修改成功！" << endl;
			return "1";
		}
		else
		{
			cout << "两次输入的密码不相同！" << endl;
			return "2";
		}
	}
	else
		cout << "旧密码错误，修改密码失败！" << endl;
	        return "3";
}

Student InfoManageService::lookStudentInfo(const std::string &sid)
{
	StudentDB sDB;
	Student stu = sDB.selectById(sid);
	return stu;
}

Teacher InfoManageService::lookTeacherInfo(const std::string &tid)
{
	TeacherDB tDB;
	Teacher t = tDB.selectById(tid);
	return t;
}

void InfoManageService::stuEditInfo(Student &stu)
{
	StudentDB sDB;
	sDB.update(stu);
}

void InfoManageService::teacEditInfo(Teacher &teac)
{
	TeacherDB tDB;
	tDB.update(teac);
}

InfoManageService::~InfoManageService()
{
}